package com.jeez.module.sys.service;

import com.jeez.common.jpa.service.JpaCurdService;
import com.jeez.module.sys.entity.SysUser;
import com.jeez.module.sys.repository.SysUserExtRepository;
import com.jeez.module.sys.repository.SysUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: Felix
 * @date: 2018-7-1
 * @version: v1.0
 * @description:
 */
@Service
@Transactional
public class UserService extends JpaCurdService<Long, SysUserRepository, SysUser> {

    @Autowired
    private SysUserExtRepository sysUserExtRepository;

    /**
     * 根据用户ID查找用户
     * @param id
     * @return
     */
    public SysUser findById(Long id) {
        return getRespository().findOne(id);
    }

    /**
     * 根据登录名查找用户
     * @param userCode
     * @return
     */
    public SysUser findByUserCode(String userCode) {
        return getRespository().findByUserCode(userCode);
    }


    /**
     * 分页查询用户信息
     * @param pageable
     * @return
     */
    public Page<SysUser> listUser(SysUser user, Pageable pageable) {
        String condition = "userCode=?";
        return getRespository().findAll(condition, pageable, user.getUserCode());
    }
}
